var path = require("path");
var webpack = require("webpack");
let HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
    entry: {
        app: __dirname + '/src/app.js',
        vender: ['react', 'react-dom', 'react-router-dom', 'react-loadable']
    },
    output: {
        path: __dirname + '/dist',
        filename: '[name].js'
    },
    resolve: {
        extensions: ['*', '.js', '.jsx'],
        alias: {
            'utils': path.join(__dirname, "/src/utils")
        }
    },
    module: {
        rules: [{
            test: /(\.jsx|\.js)$/,
            use: [{
                loader: 'babel-loader',
                options: {
                    presets: [
                        ["babel-preset-es2015", {"loose":true, "modules": false}],
                        "babel-preset-stage-0",
                        "babel-preset-react"
                    ],
                    plugins: [
                        "babel-plugin-syntax-dynamic-import",
                        ["babel-plugin-import", {
                            "libraryName": "antd",
                            "libraryDirectory": "lib",
                            "style": "css"
                        }]
                    ]
                }
            }],
            exclude: /node_modules/
        }, {
            test: /\.css$/,
            use: [{
                loader: 'style-loader'
            }, {
                loader: 'css-loader'
            }]
        }]
    },
    plugins: [
        new HtmlWebpackPlugin({
            inject: 'body',
            template: 'src/index.html'
        }),

        new webpack.optimize.CommonsChunkPlugin({
            name: 'vender',
            minChunks: 2
        }),

        new webpack.optimize.CommonsChunkPlugin({
            name: 'common',
            minChunks: 2
        })
    ]
}